package com.example.mystore.controller;

import com.example.mystore.model.Category;
import com.example.mystore.model.Product;
import com.example.mystore.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/categories")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    // 获取所有分类
    @GetMapping
    public List<Category> getAllCategories() {
        return categoryService.getAllCategories();
    }

    // 获取分类下的商品
    @GetMapping("/{categoryId}/products")
    public List<Product> getProductsByCategory(
            @PathVariable Long categoryId,
            @RequestParam double minPrice,
            @RequestParam double maxPrice,
            @RequestParam String sort) {
        return categoryService.getProductsByCategory(categoryId, minPrice, maxPrice, sort);
    }
}
